package uba.ing2.subite.services.mocks;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import uba.ing2.subite.domain.Invoice;
import uba.ing2.subite.domain.PaymentCard;
import uba.ing2.subite.domain.PaymentTerminal;
import uba.ing2.subite.services.PaymentAuthorizationResult;
import uba.ing2.subite.services.authorizationrules.PaymentAuthorizationRule;

/**
 * Regla "mock" para validar si una terminal de pago es o no valida.
 */
public class MockPaymentTerminalAuthorizationRule implements PaymentAuthorizationRule {
    private Set<PaymentTerminal> authorizedTerminals;

    public MockPaymentTerminalAuthorizationRule(Set<PaymentTerminal> terminals) {
        this.authorizedTerminals = terminals;
    }

    public static PaymentAuthorizationRule validTerminals(PaymentTerminal... terminals) {
        return new MockPaymentTerminalAuthorizationRule(new HashSet<PaymentTerminal>(Arrays.asList(terminals)));
    }

	@Override
	public PaymentAuthorizationResult apply(Invoice invoice, PaymentCard card) {
		return PaymentAuthorizationResult.createFromCondition(authorizedTerminals.contains(invoice.paymentTerminal()),
				"La terminal no es valida.");
	}
}
